var app = getApp();
Page({

  data: {
    status:'点击选择状态',    
    itemList: ['增加', '减少'],
    pageInfo: '',
    index: 0,   
    zzz:'2',
    date: '',
    banci:'',
    choose:'',
    info:[],
    id:'',
  },

  onLoad: function () {
    var that = this;
    if (!wx.getStorageSync('openid')) {
      app.error("请登录后再操作");
      return false;
    }
  
  },
  onShow:function(){
  },
  changezt(){
    var that = this
    wx.showActionSheet({
      itemList: ['增加', '减少'],
      success(res) {
        that.setData({ status: that.data.itemList[res.tapIndex]});
        that.setData({ choose: res.tapIndex});
        console.log(res.tapIndex)
     
      },
      fail(res) {
        console.log(res.errMsg)
      }
    })
  },
 
  
  bindPickerChange: function(e) {
  
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index3: e.detail.value
    })

  },

  bindPickerChange2: function(e) {
  
    // console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      index4: e.detail.value
    })


  },

 
  formSubmit: function (event) {
    var that = this;
    var zzz = that.data.zzz;
    console.log(zzz)
    //首先检索物料
    if(zzz == 2){
      if (event.detail.value.wuliao) {
        wx.request({
          url: app.apiUrl + '/api/data/storesearch',
          data: {
            scode:event.detail.value.wuliao,
            openid:wx.getStorageSync('openid'),
            groupid:wx.getStorageSync('groupid'),
          },
          method: 'POST',
          header: { 'content-type': 'application/x-www-form-urlencoded' },
          success: res=> {
           if(res.data.code == 1){
             that.setData({ zzz: 1});
             that.setData({ id: res.data.data.s_id});
             that.setData({ info: res.data.data});
 
           }else{
            wx.showModal({
              title: '温馨提示',
              content: res.data.msg,
              showCancel: false
            });
           }
    
          }
        })


      }else{
        app.error('请输入物料编号');
        return;
      }



    }else{
      //提交物料
      if(that.data.choose === ""){
        app.error('请选择状态');
        return;
      }
      if (event.detail.value.kucun > 0) {
       
      }else{
        app.error('请输入库存变更数量');
        return;
      }

      wx.request({
        url: app.apiUrl + '/api/data/storein',
        data: {
          choose:that.data.choose,
          stock: event.detail.value.kucun,
          openid:wx.getStorageSync('openid'),
          id:this.data.id
        },
        method: 'POST',
        header: { 'content-type': 'application/x-www-form-urlencoded' },
        success: res=> {
         if(res.data.code == 1){
          wx.showModal({
            title: '温馨提示',
            content: res.data.msg,
            showCancel: false
          });
          
          setTimeout(function () {
            wx.redirectTo({
              url: '/page/my/index',
            }) 
          }, 2000)
         }else{
          wx.showModal({
            title: '温馨提示',
            content: res.data.msg,
            showCancel: false
          });
         }
  
        }
      })
  




    }



  },


  bindKeyInput(e){
      console.log(e.detail.value)
      this.setData({ liyou: e.detail.value});
  },

  bindDateChange: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date: e.detail.value
    })
  },

  bindDateChange2: function(e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      date2: e.detail.value
    })
  },



})